struct VertIn
{
	float4 pos		: POSITION;
	float4 inNormal	: NORMAL;
	float2 texcoord	: TEXCOORD0;
};

struct VertOut
{
	float4 pos		: Position;
	float4 outNormal: NORMAL;
	float2 texcoord	: TEXCOORD0;
	float4 colour	: COLOR
};

struct PixelIn
{
	float4 finalColour	: COLOR;
}

// Vertex Shader
VertOut mainVS(	VertIn input,
				uniform float4x4 worldViewProjMat
				uniform float4x4 worldMat,
				uniform float4 cameraPos,
				uniform float4 lightPos,
				uniform float4 ambientColour,
				uniform float4 diffuseColour,
				uniform float4 specularColour,
				uniform float shininess
			)
{
	// Initialise output with zero's
	VertOut output	= (VertOut)0;
	
	// World View Projection Matrix - OGRE is MATRIX by POS
	output.pos		= mul(worldViewProjMat, input.pos);
	float3 worldPos	= mul(worldMat, input.pos);
	
	float3 lightDir	= normalize(lightPos - worldPos);
	float3 viewDir	= normalize(cameraPos- worldPos);
	
	float dotNormL	= dot(lightDir, input.inNormal);
	float diffuse	= saturate(dotNormL);
	
	float3 ref		= (input.inNormal * 2 * dotNormL) - lightDir;
	float dotRV		= dot(ref, viewDir);
	float specular	= pow(saturate(dotRV), 15);
	
	// Calcuate Texture Coords
	output.texcoord	= input.texcoord;
	// Calculate normal
	output.outNormal= input.inNormal;
	// combine the two lights
	output.colour	= diffuse * diffuseColour + specular * specularColour + ambientColour;

	return output;
}

// Fragment Shader
float4 mainPS(	PixelIn input,
				uniform sampler2D img : register(s0)
			) : COLOR0
{
	float4 finLight	= input.finalColour;
	float4 myTex 	= tex2D(img, input.texcoord);
	
	return myTex + finLight;
}